Skip to content

fix: add reasoning-stripping handoff helpers#2749

Closed
sztoplover-bit wants to merge 1 commit into
openai:mainfrom
sztoplover-bit:fix/remove-reasoning-handoff
Closed

fix: add reasoning-stripping handoff helpers#2749
sztoplover-bit wants to merge 1 commit into
openai:mainfrom
sztoplover-bit:fix/remove-reasoning-handoff

Conversation

@sztoplover-bit
Copy link
Copy Markdown

Summary

This PR adds built-in helpers for handing off from reasoning models to non-reasoning models.

Changes:

  • add strip_reasoning_items(...) to remove reasoning items from plain input history
  • add remove_reasoning_items(...) as a reusable handoff filter
  • strip orphaned assistant message IDs when reasoning items are removed from history, to avoid follow-up Responses API validation errors
  • add focused regression tests for the new helpers

Why

Issue #569 reports failures when reasoning-model output history is passed to a non-reasoning model.

This PR takes the narrow, low-risk path discussed in the issue by adding built-in filtering helpers rather than changing default history conversion behavior across the SDK.

Testing

  • ruff check src/agents/extensions/handoff_filters.py tests/test_extension_filters.py
  • PYTHONPATH=src /Users/lvxianping/project/llm_study/bug_ass/openai-agents-python/.venv/bin/python -m pytest tests/test_extension_filters.py -q

Related

@github-actions github-actions Bot added the bug Something isn't working label Mar 21, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d847b32ccf

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +84 to +85
filtered_pre_handoff_items = _remove_reasoning_from_items(handoff_input_data.pre_handoff_items)
filtered_new_items = _remove_reasoning_from_items(handoff_input_data.new_items)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Strip assistant IDs from message run items after reasoning removal

remove_reasoning_items removes ReasoningItem entries from new_items but never sanitizes assistant message IDs in those same run items. In handoffs where a turn emits both reasoning and an assistant message, execute_handoffs uses filtered.new_items for the next model input, and MessageOutputItem.to_input_item() preserves the message id; after reasoning is dropped, that ID can still be orphaned and trigger the Responses API validation error this helper is intended to avoid. The same orphaned-ID cleanup needs to be applied to message run items (or to derived input_items) when reasoning is removed from new_items.

Useful? React with 👍 / 👎.

Comment on lines +87 to +91
return HandoffInputData(
input_history=filtered_history,
pre_handoff_items=filtered_pre_handoff_items,
new_items=filtered_new_items,
run_context=handoff_input_data.run_context,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve input_items when constructing filtered handoff data

remove_reasoning_items constructs a fresh HandoffInputData but does not carry over input_items. If this helper is composed with another filter that sets input_items (the field that controls what is sent to the next model while keeping full session history), this function silently resets it to None, causing the runtime to fall back to new_items and undo the caller’s filtering intent. Return via handoff_input_data.clone(...) or explicitly pass through input_items.

Useful? React with 👍 / 👎.

@seratch
Copy link
Copy Markdown
Member

seratch commented Mar 21, 2026

The issue is resolved by #2700

@seratch seratch closed this Mar 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants